using micromsg;
using MicroMsg.Common.Event;
using MicroMsg.Common.Utils;
using MicroMsg.Network;
using MicroMsg.Protocol;
using MicroMsg.Scene;
using System;
using System.Collections.Generic;
namespace MicroMsg.Plugin.Shake.Scene
{
	public class NetSceneBatchGetShakeTranImg : NetSceneBaseEx<BatchGetShakeTranImgRequest, BatchGetShakeTranImgResponse, BatchGetShakeTranImgRequest.Builder>
	{
		private const string TAG = "NetSceneBatchGetShakeTranImg";
		private const int MAX_TIMES = 3;
		private int mContinueTimes;
		private List<string> mUrlList;
		public bool doScene(List<string> urlList)
		{
			if (urlList != null && urlList.get_Count() > 0)
			{
				this.mUrlList = urlList;
				this.mContinueTimes = 0;
				return this.doScene();
			}
			return false;
		}
		private bool doScene()
		{
			Log.smethod_4("NetSceneBatchGetShakeTranImg", "doscene in");
			base.beginBuilder();
			this.mBuilder.BaseRequest = NetSceneBase.makeBaseRequest(0);
			this.mBuilder.Count = (uint)this.mUrlList.get_Count();
			using (List<string>.Enumerator enumerator = this.mUrlList.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					string current = enumerator.get_Current();
					this.mBuilder.WebUrlListList.Add(Util.toSKString(current));
				}
			}
			this.mSessionPack.mCmdID = 129;
			base.endBuilder();
			return true;
		}
		protected override void onFailed(BatchGetShakeTranImgRequest request, BatchGetShakeTranImgResponse response)
		{
			PackResult lastError = base.getLastError();
			Log.smethod_4("NetSceneBatchGetShakeTranImg", "onFailed in PackResult =" + lastError);
			if (lastError == PackResult.BEEN_CANCELLED)
			{
				return;
			}
			EventCenter.postEvent(EventConst.ON_NETSCENE_SHAKE_ERR, null, null);
		}
		protected override void onSuccess(BatchGetShakeTranImgRequest request, BatchGetShakeTranImgResponse response)
		{
			Log.smethod_4("NetSceneBatchGetShakeTranImg", "onSuccess in");
			RetConst ret = (RetConst)response.BaseResponse.Ret;
			if (ret != RetConst.MM_OK)
			{
				EventCenter.postEvent(EventConst.ON_NETSCENE_SHAKE_ERR, null, null);
				return;
			}
			if (this.mUrlList.get_Count() < response.ImgUrlListList.get_Count())
			{
				if (this.mContinueTimes > 3)
				{
					Log.smethod_1("NetSceneBatchGetShakeTranImg", "reach max continue times");
					EventCenter.postEvent(EventConst.ON_NETSCENE_SHAKE_ERR, ret, null);
					return;
				}
				using (IEnumerator<ShakeTranImgGetItem> enumerator = response.ImgUrlListList.GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						ShakeTranImgGetItem current = enumerator.get_Current();
						this.mUrlList.Remove(current.ImgUrl);
					}
				}
				ShakeService.delayToExec(2, delegate
				{
					this.mContinueTimes++;
					this.doScene();
				});
			}
			EventCenter.postEvent(EventConst.ON_NETSCENE_SHAKE_SUCCESS, null, null);
		}
	}
}
